import 'package:hi_common/util/color.dart';
import 'package:flutter/material.dart';
import 'package:provider/provider.dart';

bool isDarkTheme(BuildContext context) {
  return context.watch<ThemeProvider>().isDark();
}

class ThemeProvider extends ChangeNotifier {
  ThemeMode mode = ThemeMode.light;

  ///切换主题
  void toggleMode(ThemeMode mode) {
    this.mode = mode;
    notifyListeners();
  }

  bool isDark() {
    return mode == ThemeMode.dark;
  }

  ThemeData getTheme({bool isDark = false}) {
    return ThemeData(
        brightness: isDark ? Brightness.dark : Brightness.light,
        primaryColor: isDark ? HiColor.dark_bg : white,
        unselectedWidgetColor: isDark ? HiColor.dark_bg : white,
        bottomNavigationBarTheme: isDark
            ? BottomNavigationBarThemeData(backgroundColor: Colors.grey[850])
            : const BottomNavigationBarThemeData(backgroundColor: Colors.white),
        cardTheme: isDark
            ? CardThemeData(color: Colors.grey[850])
            : const CardThemeData(color: Colors.white),
        indicatorColor: isDark ? primary[50] : white,
        scaffoldBackgroundColor: isDark ? HiColor.dark_bg : white);
  }
}
